<?php
namespace Siter\Controller;

class AdController extends Controller {

    public function index() {
        $m    = D('VAd');
        $expr = [
            'plan_status' => 1,
            'status'      => 1,
        ];

        $this->indexExpr = $expr;    //只显示处于投放状态的计划所属的广告
        $this->sortExpr = 'plan_id ASC';
        $page = $m->where($this->indexExpr)->order($this->sortExpr)->page2();

        $this->assign('page', $page)->display();
    }

    public function getByPlanId() {
        $planId  = I('get.plan_id', 0, 'intval');
        $expr    = ['plan_id' => $planId, 'status' => 1];
        $adModel = D('Ad');

        if ($records = $adModel->where($expr)->select()) {
            foreach ($records as $k => $v) {
                if ($v['type'] == 'zl' && $tmp = $adModel->parseZlCode($v['code'])) {
                    $records[$k] = array_merge($records[$k], $tmp);
                }
            }
        }

        $msg = $records
               ? ['s' => true,  'm' => $records]
               : ['s' => false, 'm' => '未找到广告数据'];

        showJson($msg);
    }
	
	//增加方法
	
	public function getAd(){
		$this->display();
	}
	
	public function AdManage(){
		$this->display();
	}
	
	public function AdReport(){
		$this->display();
	}
	
	public function getAdCode(){
	   $this->display();	
	}
	
	public function editAd(){
		
		$this->display();
	}

    /**
     * show
     * 显示广告
     *
     * @return void
     */
    public function show() {
        $id = I('get.id', 0, 'intval');

        if(empty($id)) {
            throw new ThinkException('参数不完整');
        }

        $m = D2();

        if(!$rAd = $m->getByAdId($id)) {
            throw new ThinkException('没有找到广告');
        }

        header("Content-Type:text/html; charset=utf-8");
        echo $m->getOutHtml($rAd['type'], $rAd['url'], $rAd['width'], $rAd['height'], $rAd['code']);
    }
	
	
    
}
